<?php
//本地测试地址
$url = 'http://dev.heikeji.com/api/';
//$url = 'http://xs.chindor.com/api/';
$member_id =1;
$token = 'c8577755941783e7db722030ec1e597e';
/*********************************************基础模块start**********************************************/
//首页
//$result = post($url.'home/default/index',array());
/*********************************************基础模块end**********************************************/

/*********************************************会员登录注册接口测试start**********************************************/
//会员登录
//$result = post($url.'member/default/login',array('login_account'=>'13795423417','password'=>'123456'));

//会员注册
// $result = post($url.'member/default/register',array('login_account'=>'13795423417', 'password'=>'123456', 'code'=>'690638'));

//会员重置密码
//$result = post(
//    $url.'member/default/reset',
//    array('member_id'=>$member_id,'token'=>$token,'new_password'=>'12345678'));

//验证码
//$result = post($url.'member/code/create',array('mobile'=>'13795423417','type'=>1));
/*********************************************会员登录注册接口测试end**********************************************/

print_r ($result);


/**
 *
 *
 * 发送POST请求
 *
 * @param string $url
 * @param array $post
 * @throws Exception
 * @return string
 */
function post($url, $post = null)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FAILONERROR, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    //https 请求
    if(strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https" )
    {
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    }
    if (is_array($post) && 0 < count($post))
    {
        $post_body_string = "";
        $post_multipart = false;
        foreach ($post as $k => $v)
        {
            if("@" != substr($v, 0, 1))//判断是不是文件上传
            {
                $post_body_string .= "$k=" . urlencode($v) . "&";
            }
            else//文件上传用multipart/form-data，否则用www-form-urlencoded
            {
                $post_multipart = true;
            }
        }
        curl_setopt($ch, CURLOPT_POST, true);
        if ($post_multipart)
        {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        }
        else
        {
            curl_setopt($ch, CURLOPT_POSTFIELDS, substr($post_body_string,0,-1));
        }
    }
    $reponse = curl_exec($ch);

//        if (curl_errno($ch))
//        {
//            throw new Exception(curl_error($ch), 0);
//        }
//        else
//        {
//            $http_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//            if (200 !== $http_status_code)
//            {
//                throw new Exception($reponse,$http_status_code);
//            }
//        }
    curl_close($ch);
    return $reponse;
}
